﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // fill the table contents
        string searchString = Request.QueryString["Search"];
        titleLabel.Text = "Поиск товара";
        descriptionLabel.Text = "Вы ищите <font color=\"red\">"
        + searchString + "</font>.";
        // set the title of the page
        this.Title = PresentsConfiguration.SiteName +
        " : Product Search : " + searchString;
        PopulateControls();
    }

    private void PopulateControls()
    {
        // Retrieve Search string from query string
        string searchString = Request.QueryString["Search"];
        // How many pages of products?
        int howManyPages = 1;
        string page = "3";
        // If performing a product search
        if (searchString != null)
        {
            // Retrieve AllWords from query string
            string allWords = Request.QueryString["AllWords"];
            // Perform search
            ListView1.DataSource = CatalogAccess.Search(searchString, allWords,
            page, out howManyPages);
            ListView1.DataBind();
        }
    }

    // fires when an Add to Cart button is clicked
    protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        // The CommandArgument of the clicked Button contains the ProductID
        string productId = e.CommandArgument.ToString();
        // Add the product to the shopping cart
        ShoppingCartAccess.AddItem(productId);
    }
}